/**
 * 
 */
package uno.component;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import uno.net.UnoPlay;
import uno.net.UnoPlayer;
import uno.utilities.RulesVerifier;
import uno.utilities.URNResolver;

/**
 * @author mattialambertini
 *
 */
public class OneStopCard extends Card {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2371595855245106731L;

	/**
	 * @param width
	 * @param height
	 * @param value
	 * @param parent
	 */
	public OneStopCard(int width, int height, CardValue value, HandOfCard parent) {
		super(width, height, value, parent);
		
	}
	
	/* (non-Javadoc)
	 * @see uno.component.Card#addCardListeners()
	 */
	@Override
	protected void addCardClickListeners() {
		
		addMouseListener(new MouseAdapter(){
			
			public void mouseClicked(MouseEvent e) {
				
				super.mouseClicked(e);
				Card tmpCard = (Card)e.getSource();
				HandOfCard hocParent = getParent();

				RulesVerifier rvf = new RulesVerifier(hocParent.getOwner().getPlayedCardsList());
				//controlla se e' corretto giocare una carta
				if(rvf.checkPlaySoundness(tmpCard)){
					hocParent.removeCard(tmpCard);//rimuovo dalla mano del giocatore la carta
					hocParent.repaint();

					clickBehavior(hocParent, tmpCard);
				}
			}
			
			/**
			 * Metodo in cui e' implementato il comportamento di questa carta quando 
			 * viene giocata.
			 * */
			private void clickBehavior(HandOfCard hocParent, Card playedCard){
				
				System.out.println("Faccio saltare il turno al giocatore successivo");
				
				UnoPlayer currentPlayer = hocParent.getOwner();
				UnoPlay play = new UnoPlay(currentPlayer.getGameStatus().getID() + 1, currentPlayer.getMyPlayerID(), URNResolver.cardToURN(playedCard), currentPlayer.getDeck().getDeckSize(), currentPlayer.getHandOfCard().getHOCSize());
				currentPlayer.updateStatus(play);
				
			}
		

		});
	}

}
